package com.zwk.views;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import com.zwk.model.*;
public class WKStdFuncPortalFrame {

	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH = 500;
	private static final int DEFAULT_HEIGHT = 450;
	public static JFrame frame;
	JFrame parentFrame;
	public WKStdFuncPortalFrame(String id) {
		frame = new JFrame();
		frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		frame.setTitle("学生考勤系统");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenWidthpx = screenSize.width;
		int screenHeightpx = screenSize.height;
		frame.setLocation(screenWidthpx / 3, screenHeightpx / 3);
		frame.setLocationByPlatform(false);
		
		Image image = new ImageIcon(this.getClass().getResource("/WKImage/top1.jpg")).getImage();
		frame.setIconImage(image);
		WKStdFuncPortalPanel loginPanel = new WKStdFuncPortalPanel(id);
		frame.setContentPane(loginPanel);
		frame.setLayout(null);
		frame.setVisible(true);
		
	}
	private class WKStdFuncPortalPanel extends JPanel {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		JPanel stuPanel;
		JLabel stuPicLabel;
	    JLabel idLabel;
	    
	    JPanel buttonPanel;
	    JButton seeMsgButton;
	    JButton resetMsgButton;
	    JButton resetPwdButton;
	    JButton seeTchButton;
	    JButton seeClaButton;
	    
	    JPanel numPanel;
	    JLabel numLabel;
	    JTextField numTextField;
	    JButton selectButton;
	    
	    JPanel tablePanel;
	    JTable reasonTable;
	    
	    public WKStdFuncPortalPanel(final String id) {
	    	
	    	WKStdLoginOperator student = new WKStdLoginOperator();
	    	student.getInfo(id);
	    	//头像部分
	    	stuPanel = new JPanel();
	    	stuPanel.setBounds(0, 0, 150, 145);
	    	stuPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
	    	stuPanel.setBorder(BorderFactory.createEtchedBorder());
	    	stuPicLabel = new JLabel();
	    	stuPicLabel.setSize(150, 100);
	    	ImageIcon image = new ImageIcon(this.getClass().getResource("/WKImage/header.jpg"));
	    	image.setImage(image.getImage().getScaledInstance(stuPicLabel.getWidth(), stuPicLabel.getHeight(), Image.SCALE_DEFAULT));;
	    	stuPicLabel.setIcon(image);
	    	stuPanel.add(stuPicLabel);
	    	idLabel = new JLabel(student.student.getId());
	    	stuPanel.add(idLabel);
	    	add(stuPanel);
	    	
	    	//按钮部分
	    	buttonPanel = new JPanel();
	    	buttonPanel.setBounds(0, 150, 150, 265);
//	    	buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
	    	buttonPanel.setBorder(BorderFactory.createEtchedBorder());
	    	seeMsgButton = new JButton("查看个人信息");
	        seeMsgButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKSelectStdMsgView stdView = new WKSelectStdMsgView(id);
	    			frame.dispose();
	    		}
	    	});
		    resetMsgButton = new JButton("修改个人信息");
		    resetMsgButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKSelectStdMsgView stdView = new WKSelectStdMsgView(id);
	    			frame.dispose();
	    		}
	    	});
		    resetPwdButton = new JButton("修改个人密码");
		    resetPwdButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKResetStdPwdView stdView = new WKResetStdPwdView(id);
	    			frame.dispose();
	    		}
	    	});
		    seeTchButton = new JButton("查看教师信息");
		    seeTchButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKSeeTchMsgView stdView = new WKSeeTchMsgView(id);
	    			frame.dispose();
	    		}
	    	});
		    seeClaButton = new JButton("查看课程信息");
		    seeClaButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKSeeClassView stdView = new WKSeeClassView(id);
	    			frame.dispose();
	    		}
	    	});
	    	buttonPanel.add(seeMsgButton);
	    	buttonPanel.add(resetMsgButton);
	    	buttonPanel.add(resetPwdButton);
	    	buttonPanel.add(seeTchButton);
	    	buttonPanel.add(seeClaButton);
	    	add(buttonPanel);
	       
	    	//查询考勤记录
	    	numPanel = new JPanel();
	    	numPanel.setBounds(160, 0, 340, 70);
	    	numPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
	    	numPanel.setBorder(BorderFactory.createEtchedBorder());
		    numTextField = new JTextField(18);
		    selectButton = new JButton("查询");
		    numLabel = new JLabel("请输入要查询考勤记录的课程编号");
		    numPanel.add(numLabel);
		    numPanel.add(numTextField);
		    numPanel.add(selectButton);	    	
	    	add(numPanel);
	    	
	    	//数据展示
	    	tablePanel = new JPanel();
	    	tablePanel.setBounds(160, 70, 340, 345);
	    	tablePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
	        tablePanel.setBorder(BorderFactory.createEtchedBorder());
	        
	    	String[] headers = {"考勤时间", "考勤课程", "考勤结果"};
	    	Object[][] cellData = null;
	    	DefaultTableModel model = new DefaultTableModel(cellData, headers) {
	    		public boolean isCellEditable(int row, int column) {
	    			return false;
	    		}
	    	};
	    	reasonTable = new JTable(model);
	    	reasonTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
	    	reasonTable.setPreferredScrollableViewportSize(new Dimension(300, 60));
	    	reasonTable.setShowGrid(true);
	    	reasonTable.setShowHorizontalLines(true);
	    	reasonTable.setShowVerticalLines(true);
	    	TableColumn firsetColumn = reasonTable.getColumnModel().getColumn(0);
	    	firsetColumn.setPreferredWidth(110);
	    	firsetColumn.setMaxWidth(110);
	    	firsetColumn.setMinWidth(110);
	    	DefaultTableModel tableModel = (DefaultTableModel)reasonTable.getModel();
	    	int count = 3;
	    	tableModel.setColumnCount(count);
	    	reasonTable.setRowHeight(20);
	    	tableModel.setRowCount(2);
	    	JScrollPane scrollPane = new JScrollPane(reasonTable);
	    	tablePanel.add(scrollPane, BorderLayout.CENTER);
	    	add(tablePanel);
	    }
	
	}
	
	
}
